package com.zhangliuliu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangliuliu.bean.MedicamentBean;
import com.zhangliuliu.dao.MedicDao;
import com.zhangliuliu.service.MedicService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class MedicServiceImpl extends ServiceImpl<MedicDao, MedicamentBean> implements MedicService{

    @Override
    public void add(MedicamentBean medicamentBean) {
        save(medicamentBean);
    }

    @Override
    public IPage<MedicamentBean> cutByItem(int pageNo, int pageSize, String name, String prevent, String type) {
        Page<MedicamentBean> Page = new Page<>(pageNo, pageSize);
         QueryWrapper wrapper = new QueryWrapper();

        if (name!=null&& !name.equals("")){
            wrapper.eq("medic_name",name);
        }
        if (prevent!=null&& !prevent.equals("")){
            wrapper.eq("treatment",prevent);
        }
        if (type!=null && !type.equals("")){
            wrapper.eq("medic_type",type);
        }
      IPage<MedicamentBean>iPage=  this.page(Page,wrapper);
        return iPage;
    }

    @Override
    public IPage<MedicamentBean> cutAll(int pageNo, int pageSize) {
       Page<MedicamentBean> Page = new Page<>(pageNo, pageSize);
       return this.page(Page,null);
    }
}
